package com.sven.consumer;

import com.alibaba.fastjson2.JSON;
import com.netflix.appinfo.InstanceInfo;
import com.netflix.discovery.EurekaClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.List;

@Slf4j
@RestController
public class MainController2 {

    @Autowired
    RestTemplate restTemplate;

    @GetMapping("/client4")
    public String client4(){
        // 自动处理URL，需要@LoadBalanced注解，转化成请求的服务器地址
        String url = "http://EUREKA-PROVIDER/getHi";
        String str = restTemplate.getForObject(url, String.class);
        log.info("getHi的结果：{}", str);
        return str;
    }


}

